/***********************************
 * 删除file表中id为fileID的记录，
 *
 * 成功返回1，失败返回-1
 ***********************************/

#include <mysql/mysql.h>
#include <string.h>
#include <stdio.h>

int deleteFile(int fileID)
{
	MYSQL *conn;

	char *server="localhost";
	char *user="root";
	char *password="1234";
	char *database="netdisk";
	char query[200] = {0};
	char buf[]="delete from file where id=";
    //拼接查询语句
    sprintf(query, "%s%d", buf, fileID);
    /* puts(query); */

	int queryRet;

	conn = mysql_init(NULL);

	if(!mysql_real_connect(conn, server, user, password, database, 0, NULL, 0))
	{
		printf("Error connecting to database: %s\n", mysql_error(conn));
	}
    else
    {
		/* printf("Connected...\n"); */
	}

	queryRet = mysql_query(conn, query);
	if(queryRet)
	{
		printf("Error making query:%s\n",mysql_error(conn));
	}
    else
    {
        unsigned long ret = mysql_affected_rows(conn);
        if(ret)
        {
            printf("delete success, delete row=%lu\n", ret);
        }
        else
        {
            printf("delete failed,mysql_affected_rows: %lu\n", ret);
        }
	}

	mysql_close(conn);

	return 0;
}
